#include "jabstractinputpanel_p.h"
#include "widgets/jvkbutton.h"

#include <QAbstractButton>
#include <QResizeEvent>
#include <QMouseEvent>

namespace QTE
{

JAbstractInputPanel::
JAbstractInputPanel(JAbstractInputPanelPrivate *d_ptr, QWidget *parent) :
	QWidget(parent),
	d_ptr(d_ptr)
{
	Q_ASSERT(d_ptr);
	d_ptr->init(this);
	d_ptr->mapperInit();
	d_ptr->m_lastSize = size();
}

JAbstractInputPanel::JAbstractInputPanel(QWidget *parent) :
	JAbstractInputPanel(new JAbstractInputPanelPrivate(), parent)
{

}

JAbstractInputPanel::~JAbstractInputPanel()
{

}

void JAbstractInputPanel::reset()
{

}

void JAbstractInputPanel::keyClicked(QAbstractButton*)
{

}

void JAbstractInputPanel::backSpace()
{
	keyClicked(d_ptr->m_backSpaceButton);
	emit keyInput(Qt::Key_Backspace);
}

void JAbstractInputPanel::resizeEvent(QResizeEvent *event)
{
	QWidget::resizeEvent(event);
	if( isHidden() )
		return ;

	qreal wRatio = J_SCT(qreal, event->size().width()) / d_ptr->m_lastSize.width();
	qreal hRatio = J_SCT(qreal, event->size().height()) / d_ptr->m_lastSize.height();

	if( wRatio > -0.00000001 or hRatio > -0.00000001 )
	{
		d_ptr->layoutAdaptation(wRatio, hRatio);
		d_ptr->m_lastSize = size();
	}
}

} //namespace QTE
